<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>clicktoeditwrapper.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_editor_clicktoeditwrapper.js.html">clicktoeditwrapper.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A wrapper around a goog.editor.Field
<a name="line17"></a> * that listens to mouse events on the specified un-editable field, and makes
<a name="line18"></a> * the field editable if the user clicks on it. Clients are still responsible
<a name="line19"></a> * for determining when to make the field un-editable again.
<a name="line20"></a> *
<a name="line21"></a> * Clients can still determine when the field has loaded by listening to
<a name="line22"></a> * field&#39;s load event.
<a name="line23"></a> *
<a name="line24"></a> * @author nicksantos@google.com (Nick Santos)
<a name="line25"></a> */
<a name="line26"></a>
<a name="line27"></a>goog.provide(&#39;goog.editor.ClickToEditWrapper&#39;);
<a name="line28"></a>
<a name="line29"></a>goog.require(&#39;goog.Disposable&#39;);
<a name="line30"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line31"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line32"></a>goog.require(&#39;goog.dom&#39;);
<a name="line33"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line34"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line35"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line36"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line37"></a>goog.require(&#39;goog.editor.Field.EventType&#39;);
<a name="line38"></a>goog.require(&#39;goog.editor.range&#39;);
<a name="line39"></a>goog.require(&#39;goog.events.BrowserEvent.MouseButton&#39;);
<a name="line40"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line41"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line42"></a>
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>/**
<a name="line46"></a> * Initialize the wrapper, and begin listening to mouse events immediately.
<a name="line47"></a> * @param {goog.editor.Field} fieldObj The editable field being wrapped.
<a name="line48"></a> * @constructor
<a name="line49"></a> * @extends {goog.Disposable}
<a name="line50"></a> */
<a name="line51"></a>goog.editor.ClickToEditWrapper = function(fieldObj) {
<a name="line52"></a>  goog.Disposable.call(this);
<a name="line53"></a>
<a name="line54"></a>  /**
<a name="line55"></a>   * The field this wrapper interacts with.
<a name="line56"></a>   * @type {goog.editor.Field}
<a name="line57"></a>   * @private
<a name="line58"></a>   */
<a name="line59"></a>  this.fieldObj_ = fieldObj;
<a name="line60"></a>
<a name="line61"></a>  /**
<a name="line62"></a>   * DOM helper for the field&#39;s original element.
<a name="line63"></a>   * @type {goog.dom.DomHelper}
<a name="line64"></a>   * @private
<a name="line65"></a>   */
<a name="line66"></a>  this.originalDomHelper_ = goog.dom.getDomHelper(
<a name="line67"></a>      fieldObj.getOriginalElement());
<a name="line68"></a>
<a name="line69"></a>  /**
<a name="line70"></a>   * @type {goog.dom.SavedCaretRange}
<a name="line71"></a>   * @private
<a name="line72"></a>   */
<a name="line73"></a>  this.savedCaretRange_ = null;
<a name="line74"></a>
<a name="line75"></a>  /**
<a name="line76"></a>   * Event handler for field related events.
<a name="line77"></a>   * @type {!goog.events.EventHandler}
<a name="line78"></a>   * @private
<a name="line79"></a>   */
<a name="line80"></a>  this.fieldEventHandler_ = new goog.events.EventHandler(this);
<a name="line81"></a>
<a name="line82"></a>  /**
<a name="line83"></a>   * Bound version of the finishMouseUp method.
<a name="line84"></a>   * @type {Function}
<a name="line85"></a>   * @private
<a name="line86"></a>   */
<a name="line87"></a>  this.finishMouseUpBound_ = goog.bind(this.finishMouseUp_, this);
<a name="line88"></a>
<a name="line89"></a>  /**
<a name="line90"></a>   * Event handler for mouse events.
<a name="line91"></a>   * @type {!goog.events.EventHandler}
<a name="line92"></a>   * @private
<a name="line93"></a>   */
<a name="line94"></a>  this.mouseEventHandler_ = new goog.events.EventHandler(this);
<a name="line95"></a>
<a name="line96"></a>  // Start listening to mouse events immediately if necessary.
<a name="line97"></a>  if (!this.fieldObj_.isLoaded()) {
<a name="line98"></a>    this.enterDocument();
<a name="line99"></a>  }
<a name="line100"></a>
<a name="line101"></a>  this.fieldEventHandler_.
<a name="line102"></a>      // Whenever the field is made editable, we need to check if there
<a name="line103"></a>      // are any carets in it, and if so, use them to render the selection.
<a name="line104"></a>      listen(
<a name="line105"></a>          this.fieldObj_, goog.editor.Field.EventType.LOAD,
<a name="line106"></a>          this.renderSelection_).
<a name="line107"></a>      // Whenever the field is made uneditable, we need to set up
<a name="line108"></a>      // the click-to-edit listeners.
<a name="line109"></a>      listen(
<a name="line110"></a>          this.fieldObj_, goog.editor.Field.EventType.UNLOAD,
<a name="line111"></a>          this.enterDocument);
<a name="line112"></a>};
<a name="line113"></a>goog.inherits(goog.editor.ClickToEditWrapper, goog.Disposable);
<a name="line114"></a>
<a name="line115"></a>
<a name="line116"></a>/**
<a name="line117"></a> * The logger for this class.
<a name="line118"></a> * @type {goog.debug.Logger}
<a name="line119"></a> * @private
<a name="line120"></a> */
<a name="line121"></a>goog.editor.ClickToEditWrapper.prototype.logger_ =
<a name="line122"></a>    goog.debug.Logger.getLogger(&#39;goog.editor.ClickToEditWrapper&#39;);
<a name="line123"></a>
<a name="line124"></a>
<a name="line125"></a>/** @return {goog.editor.Field} The field. */
<a name="line126"></a>goog.editor.ClickToEditWrapper.prototype.getFieldObject = function() {
<a name="line127"></a>  return this.fieldObj_;
<a name="line128"></a>};
<a name="line129"></a>
<a name="line130"></a>
<a name="line131"></a>/** @return {goog.dom.DomHelper} The dom helper of the uneditable element. */
<a name="line132"></a>goog.editor.ClickToEditWrapper.prototype.getOriginalDomHelper = function() {
<a name="line133"></a>  return this.originalDomHelper_;
<a name="line134"></a>};
<a name="line135"></a>
<a name="line136"></a>
<a name="line137"></a>/** @override */
<a name="line138"></a>goog.editor.ClickToEditWrapper.prototype.disposeInternal = function() {
<a name="line139"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line140"></a>  this.exitDocument();
<a name="line141"></a>
<a name="line142"></a>  if (this.savedCaretRange_) {
<a name="line143"></a>    this.savedCaretRange_.dispose();
<a name="line144"></a>  }
<a name="line145"></a>
<a name="line146"></a>  this.fieldEventHandler_.dispose();
<a name="line147"></a>  this.mouseEventHandler_.dispose();
<a name="line148"></a>  this.savedCaretRange_ = null;
<a name="line149"></a>  delete this.fieldEventHandler_;
<a name="line150"></a>  delete this.mouseEventHandler_;
<a name="line151"></a>};
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * Initialize listeners when the uneditable field is added to the document.
<a name="line156"></a> * Also sets up lorem ipsum text.
<a name="line157"></a> */
<a name="line158"></a>goog.editor.ClickToEditWrapper.prototype.enterDocument = function() {
<a name="line159"></a>  if (this.isInDocument_) {
<a name="line160"></a>    return;
<a name="line161"></a>  }
<a name="line162"></a>
<a name="line163"></a>  this.isInDocument_ = true;
<a name="line164"></a>
<a name="line165"></a>  this.mouseEventTriggeredLoad_ = false;
<a name="line166"></a>  var field = this.fieldObj_.getOriginalElement();
<a name="line167"></a>
<a name="line168"></a>  // To do artificial selection preservation, we have to listen to mouseup,
<a name="line169"></a>  // get the current selection, and re-select the same text in the iframe.
<a name="line170"></a>  //
<a name="line171"></a>  // NOTE(nicksantos): Artificial selection preservation is needed in all cases
<a name="line172"></a>  // where we set the field contents by setting innerHTML. There are a few
<a name="line173"></a>  // rare cases where we don&#39;t need it. But these cases are highly
<a name="line174"></a>  // implementation-specific, and computationally hard to detect (bidi
<a name="line175"></a>  // and ig modules both set innerHTML), so we just do it in all cases.
<a name="line176"></a>  this.savedAnchorClicked_ = null;
<a name="line177"></a>  this.mouseEventHandler_.
<a name="line178"></a>      listen(field, goog.events.EventType.MOUSEUP, this.handleMouseUp_).
<a name="line179"></a>      listen(field, goog.events.EventType.CLICK, this.handleClick_);
<a name="line180"></a>
<a name="line181"></a>  // manage lorem ipsum text, if necessary
<a name="line182"></a>  this.fieldObj_.execCommand(goog.editor.Command.UPDATE_LOREM);
<a name="line183"></a>};
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * Destroy listeners when the field is removed from the document.
<a name="line188"></a> */
<a name="line189"></a>goog.editor.ClickToEditWrapper.prototype.exitDocument = function() {
<a name="line190"></a>  this.mouseEventHandler_.removeAll();
<a name="line191"></a>  this.isInDocument_ = false;
<a name="line192"></a>};
<a name="line193"></a>
<a name="line194"></a>
<a name="line195"></a>/**
<a name="line196"></a> * Returns the uneditable field element if the field is not yet editable
<a name="line197"></a> * (equivalent to EditableField.getOriginalElement()), and the editable DOM
<a name="line198"></a> * element if the field is currently editable (equivalent to
<a name="line199"></a> * EditableField.getElement()).
<a name="line200"></a> * @return {Element} The element containing the editable field contents.
<a name="line201"></a> */
<a name="line202"></a>goog.editor.ClickToEditWrapper.prototype.getElement = function() {
<a name="line203"></a>  return this.fieldObj_.isLoaded() ?
<a name="line204"></a>      this.fieldObj_.getElement() : this.fieldObj_.getOriginalElement();
<a name="line205"></a>};
<a name="line206"></a>
<a name="line207"></a>
<a name="line208"></a>/**
<a name="line209"></a> * True if a mouse event should be handled, false if it should be ignored.
<a name="line210"></a> * @param {goog.events.BrowserEvent} e The mouse event.
<a name="line211"></a> * @return {boolean} Wether or not this mouse event should be handled.
<a name="line212"></a> * @private
<a name="line213"></a> */
<a name="line214"></a>goog.editor.ClickToEditWrapper.prototype.shouldHandleMouseEvent_ = function(e) {
<a name="line215"></a>  return e.isButton(goog.events.BrowserEvent.MouseButton.LEFT) &amp;&amp;
<a name="line216"></a>      !(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey);
<a name="line217"></a>};
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * Handle mouse click events on the field.
<a name="line222"></a> * @param {goog.events.BrowserEvent} e The click event.
<a name="line223"></a> * @private
<a name="line224"></a> */
<a name="line225"></a>goog.editor.ClickToEditWrapper.prototype.handleClick_ = function(e) {
<a name="line226"></a>  // If the user clicked on a link in an uneditable field,
<a name="line227"></a>  // we want to cancel the click.
<a name="line228"></a>  var anchorAncestor = goog.dom.getAncestorByTagNameAndClass(
<a name="line229"></a>      /** @type {Node} */ (e.target),
<a name="line230"></a>      goog.dom.TagName.A);
<a name="line231"></a>  if (anchorAncestor) {
<a name="line232"></a>    e.preventDefault();
<a name="line233"></a>
<a name="line234"></a>    if (!goog.editor.BrowserFeature.HAS_ACTIVE_ELEMENT) {
<a name="line235"></a>      this.savedAnchorClicked_ = anchorAncestor;
<a name="line236"></a>    }
<a name="line237"></a>  }
<a name="line238"></a>};
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/**
<a name="line242"></a> * Handle a mouse up event on the field.
<a name="line243"></a> * @param {goog.events.BrowserEvent} e The mouseup event.
<a name="line244"></a> * @private
<a name="line245"></a> */
<a name="line246"></a>goog.editor.ClickToEditWrapper.prototype.handleMouseUp_ = function(e) {
<a name="line247"></a>  // Only respond to the left mouse button.
<a name="line248"></a>  if (this.shouldHandleMouseEvent_(e)) {
<a name="line249"></a>    // We need to get the selection when the user mouses up, but the
<a name="line250"></a>    // selection doesn&#39;t actually change until after the mouseup event has
<a name="line251"></a>    // propagated. So we need to do this asynchronously.
<a name="line252"></a>    this.originalDomHelper_.getWindow().setTimeout(this.finishMouseUpBound_, 0);
<a name="line253"></a>  }
<a name="line254"></a>};
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>/**
<a name="line258"></a> * A helper function for handleMouseUp_ -- does the actual work
<a name="line259"></a> * when the event is finished propagating.
<a name="line260"></a> * @private
<a name="line261"></a> */
<a name="line262"></a>goog.editor.ClickToEditWrapper.prototype.finishMouseUp_ = function() {
<a name="line263"></a>  // Make sure that the field is still not editable.
<a name="line264"></a>  if (!this.fieldObj_.isLoaded()) {
<a name="line265"></a>    if (this.savedCaretRange_) {
<a name="line266"></a>      this.savedCaretRange_.dispose();
<a name="line267"></a>      this.savedCaretRange_ = null;
<a name="line268"></a>    }
<a name="line269"></a>
<a name="line270"></a>    if (!this.fieldObj_.queryCommandValue(goog.editor.Command.USING_LOREM)) {
<a name="line271"></a>      // We need carets (blank span nodes) to maintain the selection when
<a name="line272"></a>      // the html is copied into an iframe. However, because our code
<a name="line273"></a>      // clears the selection to make the behavior consistent, we need to do
<a name="line274"></a>      // this even when we&#39;re not using an iframe.
<a name="line275"></a>      this.insertCarets_();
<a name="line276"></a>    }
<a name="line277"></a>
<a name="line278"></a>    this.ensureFieldEditable_();
<a name="line279"></a>  }
<a name="line280"></a>
<a name="line281"></a>  this.exitDocument();
<a name="line282"></a>  this.savedAnchorClicked_ = null;
<a name="line283"></a>};
<a name="line284"></a>
<a name="line285"></a>
<a name="line286"></a>/**
<a name="line287"></a> * Ensure that the field is editable. If the field is not editable,
<a name="line288"></a> * make it so, and record the fact that it was done by a user mouse event.
<a name="line289"></a> * @private
<a name="line290"></a> */
<a name="line291"></a>goog.editor.ClickToEditWrapper.prototype.ensureFieldEditable_ = function() {
<a name="line292"></a>  if (!this.fieldObj_.isLoaded()) {
<a name="line293"></a>    this.mouseEventTriggeredLoad_ = true;
<a name="line294"></a>    this.makeFieldEditable(this.fieldObj_);
<a name="line295"></a>  }
<a name="line296"></a>};
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>/**
<a name="line300"></a> * Once the field has loaded in an iframe, re-create the selection
<a name="line301"></a> * as marked by the carets.
<a name="line302"></a> * @private
<a name="line303"></a> */
<a name="line304"></a>goog.editor.ClickToEditWrapper.prototype.renderSelection_ = function() {
<a name="line305"></a>  if (this.savedCaretRange_) {
<a name="line306"></a>    // Make sure that the restoration document is inside the iframe
<a name="line307"></a>    // if we&#39;re using one.
<a name="line308"></a>    this.savedCaretRange_.setRestorationDocument(
<a name="line309"></a>        this.fieldObj_.getEditableDomHelper().getDocument());
<a name="line310"></a>
<a name="line311"></a>    var startCaret = this.savedCaretRange_.getCaret(true);
<a name="line312"></a>    var endCaret = this.savedCaretRange_.getCaret(false);
<a name="line313"></a>    var hasCarets = startCaret &amp;&amp; endCaret;
<a name="line314"></a>  }
<a name="line315"></a>
<a name="line316"></a>  // There are two reasons why we might want to focus the field:
<a name="line317"></a>  // 1) makeFieldEditable was triggered by the click-to-edit wrapper.
<a name="line318"></a>  //    In this case, the mouse event should have triggered a focus, but
<a name="line319"></a>  //    the editor might have taken the focus away to create lorem ipsum
<a name="line320"></a>  //    text or create an iframe for the field. So we make sure the focus
<a name="line321"></a>  //    is restored.
<a name="line322"></a>  // 2) somebody placed carets, and we need to select those carets. The field
<a name="line323"></a>  //    needs focus to ensure that the selection appears.
<a name="line324"></a>  if (this.mouseEventTriggeredLoad_ || hasCarets) {
<a name="line325"></a>    this.focusOnFieldObj(this.fieldObj_);
<a name="line326"></a>  }
<a name="line327"></a>
<a name="line328"></a>  if (hasCarets) {
<a name="line329"></a>    var startCaretParent = startCaret.parentNode;
<a name="line330"></a>    var endCaretParent = endCaret.parentNode;
<a name="line331"></a>
<a name="line332"></a>    this.savedCaretRange_.restore();
<a name="line333"></a>    this.fieldObj_.dispatchSelectionChangeEvent();
<a name="line334"></a>
<a name="line335"></a>    // NOTE(nicksantos): Bubbles aren&#39;t actually enabled until the end
<a name="line336"></a>    // if the load sequence, so if the user clicked on a link, the bubble
<a name="line337"></a>    // will not pop up.
<a name="line338"></a>  }
<a name="line339"></a>
<a name="line340"></a>  if (this.savedCaretRange_) {
<a name="line341"></a>    this.savedCaretRange_.dispose();
<a name="line342"></a>    this.savedCaretRange_ = null;
<a name="line343"></a>  }
<a name="line344"></a>
<a name="line345"></a>  this.mouseEventTriggeredLoad_ = false;
<a name="line346"></a>};
<a name="line347"></a>
<a name="line348"></a>
<a name="line349"></a>/**
<a name="line350"></a> * Focus on the field object.
<a name="line351"></a> * @param {goog.editor.Field} field The field to focus.
<a name="line352"></a> * @protected
<a name="line353"></a> */
<a name="line354"></a>goog.editor.ClickToEditWrapper.prototype.focusOnFieldObj = function(field) {
<a name="line355"></a>  field.focusAndPlaceCursorAtStart();
<a name="line356"></a>};
<a name="line357"></a>
<a name="line358"></a>
<a name="line359"></a>/**
<a name="line360"></a> * Make the field object editable.
<a name="line361"></a> * @param {goog.editor.Field} field The field to make editable.
<a name="line362"></a> * @protected
<a name="line363"></a> */
<a name="line364"></a>goog.editor.ClickToEditWrapper.prototype.makeFieldEditable = function(field) {
<a name="line365"></a>  field.makeEditable();
<a name="line366"></a>};
<a name="line367"></a>
<a name="line368"></a>
<a name="line369"></a>//================================================================
<a name="line370"></a>// Caret-handling methods
<a name="line371"></a>
<a name="line372"></a>
<a name="line373"></a>/**
<a name="line374"></a> * Gets a saved caret range for the given range.
<a name="line375"></a> * @param {goog.dom.AbstractRange} range A range wrapper.
<a name="line376"></a> * @return {goog.dom.SavedCaretRange} The range, saved with carets, or null
<a name="line377"></a> *    if the range wrapper was null.
<a name="line378"></a> * @private
<a name="line379"></a> */
<a name="line380"></a>goog.editor.ClickToEditWrapper.createCaretRange_ = function(range) {
<a name="line381"></a>  return range &amp;&amp; goog.editor.range.saveUsingNormalizedCarets(range);
<a name="line382"></a>};
<a name="line383"></a>
<a name="line384"></a>
<a name="line385"></a>/**
<a name="line386"></a> * Inserts the carets, given the current selection.
<a name="line387"></a> *
<a name="line388"></a> * Note that for all practical purposes, a cursor position is just
<a name="line389"></a> * a selection with the start and end at the same point.
<a name="line390"></a> * @private
<a name="line391"></a> */
<a name="line392"></a>goog.editor.ClickToEditWrapper.prototype.insertCarets_ = function() {
<a name="line393"></a>  var fieldElement = this.fieldObj_.getOriginalElement();
<a name="line394"></a>
<a name="line395"></a>  this.savedCaretRange_ = null;
<a name="line396"></a>  var originalWindow = this.originalDomHelper_.getWindow();
<a name="line397"></a>  if (goog.dom.Range.hasSelection(originalWindow)) {
<a name="line398"></a>    var range = goog.dom.Range.createFromWindow(originalWindow);
<a name="line399"></a>    range = range &amp;&amp; goog.editor.range.narrow(range, fieldElement);
<a name="line400"></a>    this.savedCaretRange_ =
<a name="line401"></a>        goog.editor.ClickToEditWrapper.createCaretRange_(range);
<a name="line402"></a>  }
<a name="line403"></a>
<a name="line404"></a>  if (!this.savedCaretRange_) {
<a name="line405"></a>    // We couldn&#39;t figure out where to put the carets.
<a name="line406"></a>    // But in FF2/IE6+, this could mean that the user clicked on a
<a name="line407"></a>    // &#39;special&#39; node, (e.g., a link or an unselectable item). So the
<a name="line408"></a>    // selection appears to be null or the full page, even though the user did
<a name="line409"></a>    // click on something. In IE, we can determine the real selection via
<a name="line410"></a>    // document.activeElement. In FF, we have to be more hacky.
<a name="line411"></a>    var specialNodeClicked;
<a name="line412"></a>    if (goog.editor.BrowserFeature.HAS_ACTIVE_ELEMENT) {
<a name="line413"></a>      specialNodeClicked = goog.dom.getActiveElement(
<a name="line414"></a>          this.originalDomHelper_.getDocument());
<a name="line415"></a>    } else {
<a name="line416"></a>      specialNodeClicked = this.savedAnchorClicked_;
<a name="line417"></a>    }
<a name="line418"></a>
<a name="line419"></a>    var isFieldElement = function(node) {
<a name="line420"></a>      return node == fieldElement;
<a name="line421"></a>    };
<a name="line422"></a>    if (specialNodeClicked &amp;&amp;
<a name="line423"></a>        goog.dom.getAncestor(specialNodeClicked, isFieldElement, true)) {
<a name="line424"></a>      // Insert the cursor at the beginning of the active element to be
<a name="line425"></a>      // consistent with the behavior in FF1.5, where clicking on a
<a name="line426"></a>      // link makes the current selection equal to the cursor position
<a name="line427"></a>      // directly before that link.
<a name="line428"></a>      //
<a name="line429"></a>      // TODO(nicksantos): Is there a way to more accurately place the cursor?
<a name="line430"></a>      this.savedCaretRange_ = goog.editor.ClickToEditWrapper.createCaretRange_(
<a name="line431"></a>          goog.dom.Range.createFromNodes(
<a name="line432"></a>              specialNodeClicked, 0, specialNodeClicked, 0));
<a name="line433"></a>    }
<a name="line434"></a>  }
<a name="line435"></a>};
</pre>


</body>
</html>
